package com.qf.application.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.application.entity.Emp;
import com.qf.application.mapper.EmpMapper;
import com.qf.application.service.IEmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@Slf4j
public class EmpServiceImpl extends ServiceImpl<EmpMapper, Emp> implements IEmpService {

    // SQL是自己写的，而且还要分页
    @Override
    public IPage empPage(Map<String, Object> param) {

        // 1.先从Map中取出分页的参数和查询字段的参数
        Integer current = (Integer) param.get("current");
        Integer size = (Integer) param.get("size");

        log.debug("param:{}",param);
        // 2.封装分页的参数
        Page<Emp> page = new Page<>(current, size);

        // 3.查询数据
        return baseMapper.empPage(page,param);
    }

    @Override
    public Long getDeptCountByDeptno(Integer deptno) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("deptno",deptno);
        return baseMapper.selectCount(wrapper);
    }
}
